package com.dxk.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@EnableSwagger2
@Configuration
public class swaggerConfig {

    @Bean
    public  Docket docket1(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("A");
    }
    @Bean
    public  Docket docket2(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("B");
    }
    @Bean
    public  Docket docket3(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("C");
    }

    @Bean
    public Docket docket(Environment environment){
        //切换环境 利用enable  ,如果开启了dev 或test 环境就开启swagger 否则就关闭
        Profiles profiles=Profiles.of("dev","test");
        boolean flag = environment.acceptsProfiles(profiles);
        System.out.println(flag);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("dxk")
                .enable(flag)
                .select()
                //any :全部扫描
                //none :不扫描
                //basePackage :扫描包
                //withClassAnnotation :扫描类上的注解
                //withMethodAnnotation: 扫描方法上的注解
                .apis(RequestHandlerSelectors.basePackage("com.dxk.controller"))
                //paths  为过滤路径
               // .paths(PathSelectors.ant("/dxk/**"))
                .build();
    }

    public ApiInfo apiInfo(){

        Contact contact=new Contact("dxk", "www.baidu.com", "2537472303@qq.com");

       return new ApiInfo(
                "dxk",
                "你以为你很了解我？",
                "1.0",
                "www.dxk.com",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList()
        );

    }

}
